#include <bits/stdc++.h>

using namespace std;

class Solution {
    public:
        int minFlips(string s) {
            int n = s.size();
            int ans1 = 0, ans2 = 0;
            for(int i = 0; i < n; ++i){
                ans1 += (i & 1) ^ (s[i] == '0'); // 开头为1
                ans2 += (i & 1) ^ (s[i] == '1'); // 开头为0
            }
            int ans = min(ans1, ans2);
            for(int i = 1; i < n; ++i){
                ans1 += (((n-i+1) & 1) ^ (s[i-1] == '0')) - (((i-1) & 1) ^ (s[i-1] == '0'));
                ans2 += (((n-i+1) & 1) ^ (s[i-1] == '1')) - (((i-1) & 1) ^ (s[i-1] == '1'));
                ans = min(ans1,ans);
                ans = min(ans2,ans);
            }
            return ans;
        }
    };

int main() {
    
    //system("pause");
    return 0;
}
